package com.tangruojie.optional;

import com.tangruojie.entity.Author;
import com.tangruojie.stream.StreamDemoTest;

import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * 过滤 filter
 */
public class OptionalDemo04 {

    public static void main(String[] args) {

        List<Author> authors = StreamDemoTest.getAuthors();

        Optional<List<Author>> optionalAuthors = Optional.of(authors);
        Optional<List<Author>> authorList = optionalAuthors.filter(new Predicate<List<Author>>() {
            @Override
            public boolean test(List<Author> authors) {
                return authors.stream()
                        .distinct()
                        .anyMatch(author -> author.getAge() > 18);
            }
        });
        System.out.println(authorList);

    }

}
